<#ftl strip_whitespace=true>

<#function contains list item>
    <#list list as nextInList>
    	<#if nextInList.equals(item)><#return true></#if>
    </#list>
    <#return false>
</#function>

<#macro header entityName action success>
	"entityName" : "${entityName}",
	"action" : "${action}",
	"success" : ${success?string}
</#macro>

<#macro single entity>
	,
	"entity" : {
		<#nested entity />
	}
</#macro>

<#macro multiple entities>
	,
	"entities" : [
		<#if entities??>
			<#list entities as entity>
				{
					<#nested entity />
				}<#if entity_has_next>,</#if>
			</#list>
		</#if>
	]
</#macro>

<#macro paging page>
	,
	"paging" : {
		"page" : ${page.number?c},
		"totalPages" : ${page.totalPages?c},
		"hasContent" : ${page.hasContent()?string},
		"firstPage" : ${page.firstPage?string},
		"hasPreviousPage" : ${page.hasPreviousPage()?string},
		"hasNextPage" : ${page.hasNextPage()?string},
		"lastPage" : ${page.lastPage?string}
	}
</#macro>

<#macro errors errors>
	,
	"errors" : [
		<#list errors as error>
			{
				"type" : "${error.type}",
				"message" : "<@spring.message "error.${error.type}" />"
				<#if error.details??>
					<#list error.details?keys as key>
						<#if key?has_content>
							,
							"${key}" : "${error.details[key]}"
						</#if>
					</#list>
				</#if>
			}<#if error_has_next>,</#if>
		</#list>
	]
</#macro>
